"""
QLineEdit控件与回显模式
基本功能：输入单行文本
设置回显模式EchoMode
4种回显模式
1.Normal
2.NoEcho
3.password模式输入一个字符显示一个黑点
4.password EchoOnEdit
"""
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import *
import sys


class QLineEditEchoMode(QWidget):
    def __init__(self):
        super(QLineEditEchoMode, self).__init__()
        self.iniUI()

    def iniUI(self):
        self.setWindowTitle('文本输入框的回显模式')

        formLayout = QFormLayout()

        normalLineEdit = QLineEdit()
        normalLineEdit.setFont(QFont('微软雅黑', 10))
        noEchoLineEdit = QLineEdit()
        noEchoLineEdit.setFont(QFont('微软雅黑', 10))
        passwordLineEdit = QLineEdit()
        passwordLineEdit.setFont(QFont('微软雅黑', 10))
        passwordEchoOnEditLineEdit = QLineEdit()
        passwordEchoOnEditLineEdit.setFont(QFont('微软雅黑', 10))

        label1 = QLabel("Normal：")
        label1.setFont(QFont('微软雅黑', 10))
        formLayout.addRow(label1, normalLineEdit)

        label2 = QLabel("NoEcho：")
        label2.setFont(QFont('微软雅黑', 10))
        formLayout.addRow(label2, noEchoLineEdit)

        label3 = QLabel("Password：")
        label3.setFont(QFont('微软雅黑', 10))
        formLayout.addRow(label3, passwordLineEdit)

        label4 = QLabel("PasswordEchoOnEdit：")
        label4.setFont(QFont('微软雅黑', 10))
        formLayout.addRow(label4, passwordEchoOnEditLineEdit)

        normalLineEdit.setPlaceholderText('Normal')
        noEchoLineEdit.setPlaceholderText("NoEcho")
        passwordLineEdit.setPlaceholderText("Password")
        passwordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoOnEdit")

        normalLineEdit.setEchoMode(QLineEdit.Normal)
        noEchoLineEdit.setEchoMode(QLineEdit.NoEcho)
        passwordLineEdit.setEchoMode(QLineEdit.Password)
        passwordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)

        self.setLayout(formLayout)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QLineEditEchoMode()
    main.show()
    sys.exit(app.exec_())
